package com.jw.system.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jw.response.Result;
import com.jw.system.entity.Goods;
import com.jw.system.entity.vo.GoodsInVO;
import com.jw.system.service.GoodsInService;
import com.jw.system.service.GoodsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 商品入库表 前端控制器
 * </p>
 *
 * @author jw
 * @since 2021-04-28
 */
@RestController
@RequestMapping("/goods-in")
public class GoodsInController {

    @Autowired
    private GoodsInService goodsInService;

    /**
     * 获取商品入库列表
     *
     * @return
     */
    @ApiOperation(value = "入库列表", notes = "模糊查询入库列表")
    @PostMapping("/getGoodsInList")
    public Result getGoodsInList(@RequestParam(value = "current", required = false) Integer current,
                                 @RequestParam(value = "size", required = false) Integer size,
                                 @RequestParam(value = "audit", required = false) Boolean audit,
                                 @RequestBody GoodsInVO goodsInVO) {
        Page<GoodsInVO> goodsInList = goodsInService.getGoodsInList(current, size, audit,goodsInVO);
        return Result.ok().data("goodsIn", goodsInList.getRecords()).data("total", goodsInList.getTotal());
    }

    /**
     * 入库单详细
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "入库单明细")
    @GetMapping("/getDetail")
    public Result detail(@RequestParam(value = "id") Long id,
                         @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                         @RequestParam(value = "pageSize", defaultValue = "3") Integer pageSize) {
        Page<Goods> goodsList = goodsInService.getDetail(pageNum, pageSize, id);
        return Result.ok().data("goods", goodsList.getRecords()).data("total", goodsList.getTotal());
    }

    /**
     * 入库审核
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "入库审核")
    @GetMapping("/getApprove")
    public Result getApprove(@RequestParam(value = "id") Long id) {
        goodsInService.getApprove(id);
        return Result.ok();
    }

    /**
     * 新增入库单
     */
    @ApiOperation(value = "添加入库")
    @PostMapping("/add")
    public Result add(@RequestBody GoodsInVO goodsInVO) {
        goodsInService.add(goodsInVO);
        return Result.ok();
    }


}

